home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Integral promotion problem
- Date: 13 Mar 1996 20:25:18 -0600
- Organization: Los Alamos National Laboratory
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4i802e$45r@solutions.solon.com>
- References: <31404525.26295649@dub-news-svc-3.compuserve.com>
- <314405dd.13127805@dub-news-svc-3.compuserve.com>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <4i6foi$p2p@solutions.solon.com>
- johnb@pivotal-dm.ccmail.compuserve.com (John Bain) writes:
-
- <snip>
- JB: I.e. (assuming a is unsigned short) in evaluating ~a, a is first
- JB: promoted to int (well defined), the int value is converted to unsigned
- JB: int (well defined), ~ is applied to the unsigned value (well defined),
- JB: and the unsigned result is converted back to int (implementation
- JB: defined, if, as seems likely, the value of the unsigned int result
- JB: cannot be represented in an int.)
-
- No. I can't find any evidence for the int-->unsigned-->int
- conversion. (If anyone can find it in the standard, please correct
- me.) Actually the standard states the following:
-
- 1) a is promoted.
- 2) The bits of the int value are complemented
- 3) The value represented by the above bit pattern depends on the
- implementation.
-
- On a two's complement machine where changing from unsigned --> int
- does not involve change in bit pattern, your sequence gives the same
- result. In general it does not.
-
- Thus, for example, given any int x, if no two bit patterns represent
- the value ~x, ~~x is guaranteed equal to x. The expression
- (int)~(unsigned)(int)~(unsigned)x however is implementation defined;
- and therefore not known to equal x in general.
-
- Note that the standard does not gurantee that for unsigned y,
- (unsigned)(int) y == y even when the representation of the value
- (int)y is unique.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-